<?php
include_once('admin_global.php');
$page=new bn_page();
$grid=new bn_grid();
$theme->add_block('body');

$grid->name='pages';
$grid->delete->enable=true;
$grid->delete->caption=$lang[17];
$grid->delete->cssclass='button red';
$grid->update->enable=true;
$grid->update->caption=$lang[16];
$grid->update->cssclass='button blue';
$grid->paging->enable=true;
$grid->paging->caption=$lang[75];
$grid->paging->cssclass='button';
$grid->page_size=10;

$cid=new column;
$cid->field_name='id';
$cid->hide=true;
$grid->columns->append($cid);

$ctitle=new column;
$ctitle->template='
<label name="label" id="label"><%title%></label>
<br />
<input type="text" size="50" readonly="readonly" name="url" id="url" value="<%url%>" class="input-text"/>
<br />
<span name="text" id="text"><%text%></span>';
$grid->columns->append($ctitle);

$cgad=new column;
$cgad->field_name='gadname';
$grid->columns->append($cgad);

$cstate=new column;
$cstate->field_name='status';
$cstate->template='<input type="submit" name="state" id="state" value="<%status%>" data_id="<%status%>" class="button"/>';
$grid->columns->append($cstate);

$theme->add_script('
$("#state").live("click",function(){
    var id=$(this).closest("tr").find("td :eq(0)").html();
    $.post(window.location.href,{cmd:"state",id:id,state:$(this).attr("data_id"),pag:$("#pages_page").val()},function(data){
        $("#show").html(data);     
    });
});');

$theme->add_script($grid->command_script('#show'));


if(isset($_POST['cmd']))
{
    extract($_POST);
    if($cmd=='state')
    {
        if($state=='disable')
        $state='enable';
        else
        $state='disable';
        $page->update_status($state,$id);
    }
    if($cmd=='delete')
    $page->delete($id);
    if($cmd=='update')
    die(bn_redirect_postdata('page.php',array('cmd'=>'update','id'=>$pages_id)));
    
    die($grid->show($page->select_all()->fetch(),$pages_page));
}
?>
<div id="show">
<?php
echo $grid->show($page->select_all()->fetch());
?>
</div>
<?php
$theme->render();
?>